﻿using System;
using Box2DX.Dynamics;
using System.Windows;
using Box2DX.Common;

namespace Expression.Samples.Physics.Behaviors
{
	/*
	public class RevoluteJointBehavior : JointBehavior<RevoluteJoint>
	{
		public static readonly DependencyProperty AnchorPointProperty = DependencyProperty.Register(
			"AnchorPointProperty",
			typeof(Point),
			typeof(RevoluteJointBehavior),
			new PropertyMetadata(
				new PropertyChangedCallback(AnchorPointChanged)));

		public static readonly DependencyProperty LowerAngleLimitProperty = DependencyProperty.Register(
			"LowerAngleLimit",
			typeof(double),
			typeof(RevoluteJointBehavior),
			new PropertyMetadata(
				-180d,
				new PropertyChangedCallback(LowerAngleLimitChanged)));

		public static readonly DependencyProperty UpperAngleLimitProperty = DependencyProperty.Register(
			"UpperAngleLimit",
			typeof(double),
			typeof(RevoluteJointBehavior),
			new PropertyMetadata(
				180d,
				new PropertyChangedCallback(UpperAngleLimitChanged)));

		public Point AnchorPoint
		{
			get { return (Point)this.GetValue(RevoluteJointBehavior.AnchorPointProperty); }
			set { this.SetValue(RevoluteJointBehavior.AnchorPointProperty, value); }
		}

		public double UpperAngleLimit
		{
			get { return (double)this.GetValue(RevoluteJointBehavior.UpperAngleLimitProperty); }
			set { this.SetValue(RevoluteJointBehavior.UpperAngleLimitProperty, value); }
		}

		public double LowerAngleLimit
		{
			get { return (double)this.GetValue(RevoluteJointBehavior.LowerAngleLimitProperty); }
			set { this.SetValue(RevoluteJointBehavior.LowerAngleLimitProperty, value); }
		}

		private Vector2 AnchorPointVector2
		{
			get { return new Vector2((float)this.AnchorPoint.X - 0.5f, -1 * (0.5f - (float)this.AnchorPoint.Y)); }
		}

		private float LowerAngleLimitRadian
		{
			get
			{
				return (((float)this.LowerAngleLimit) / 180f) * ((float)System.Math.PI);
			}
		}

		private float UpperAngleLimitRadian
		{
			get
			{
				return (((float)this.UpperAngleLimit) / 180f) * ((float)System.Math.PI);
			}
		}

		private static void AnchorPointChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
		{
			RevoluteJointBehavior revoluteJointBehavior = (RevoluteJointBehavior)obj;
			revoluteJointBehavior.RefreshJoint();
		}

		private static void LowerAngleLimitChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
		{
			RevoluteJointBehavior revoluteJointBehavior = (RevoluteJointBehavior)obj;
			revoluteJointBehavior.RefreshJoint();
		}

		private static void UpperAngleLimitChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
		{
			RevoluteJointBehavior revoluteJointBehavior = (RevoluteJointBehavior)obj;
			revoluteJointBehavior.RefreshJoint();
		}

		protected override JointDef InitializeJoint()
		{
			RevoluteJointDef revoluteJointDef = null;
			if (this.HostBody != null && this.AnchorBody != null)
			{
				revoluteJointDef = new RevoluteJointDef();
				revoluteJointDef.Initialize(this.HostBody, this.AnchorBody, this.HostBody.GetWorldPoint(this.AnchorPointVector2));
				revoluteJointDef.LowerAngle = this.LowerAngleLimitRadian;
				revoluteJointDef.UpperAngle = this.UpperAngleLimitRadian;
				revoluteJointDef.EnableLimit = true;
			}
			return revoluteJointDef;
		}
	}*/
}
